package com.dog.basics.api.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiShopAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiShopEditDto;
import com.dog.basics.bean.dto.api.mtkj.ApiShopFromDto;
import com.dog.basics.bean.dto.api.mtkj.ApiShopListDto;
import com.dog.basics.bean.vo.api.mtkj.ApiAddShopingCheckVo;
import com.dog.basics.bean.vo.api.mtkj.ApiShoppingFromVo;
import com.dog.basics.bean.vo.api.mtkj.ApiShoppingVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtShoppingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 店铺信息 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "店铺", tags = SwaggerConstants.API_ALL)
@RestController
@RequestMapping("/api/shopping")
@AllArgsConstructor
public class MtShoppingController {

    private final IMtShoppingService shoppingService;

    /**
     * 查询店铺详细信息
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据店铺id店铺信息详情", notes = "根据店铺id店铺信息详情",tags = SwaggerConstants.API_SHOPPING)
    @ApiImplicitParam(value = "店铺id", name = "id", dataType = "Long", required = true)
    @Inner
    public R<ApiShoppingVo> findById(@Valid @PathVariable("id")Long id){
        //传参为空目前没做处理
        return R.ok(shoppingService.findShoppingById(id));
    }

    @GetMapping("/findByUserId/{userId}")
    @ApiOperation(value = "根据用户id获取店铺信息详情", notes = "根据用户id获取店铺信息详情",tags = SwaggerConstants.API_SHOPPING)
    @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Long", required = true)
    public R<ApiShoppingVo> findByUserId(@Valid @PathVariable("userId")Long userId){
        //传参为空目前没做处理
        return R.ok(shoppingService.findShoppingByUserId(userId));
    }

    /**
     * 获取附近商铺信息
     *      根据经纬度查询附近商铺
     * @param page
     * @param shopFromDto
     * @return
     */
    @GetMapping("/findNearbyShops")
    @ApiOperation(value = "获取附近商铺", notes = "获取附近商铺",tags = SwaggerConstants.API_SHOPPING)
    @Inner
    public R<IPage<ApiShoppingFromVo>> findNearbyShops(PageParam page,@Valid ApiShopFromDto shopFromDto){
        return R.ok(shoppingService.nearbyShops(page, shopFromDto));
    }

    /**
     * 查询商铺
     *      1.根据名称查询商铺
     * @param: page
     * @param: shopListDto
     * @returns
     * @author hangdy
     * @date: 2020/11/12 10:57
     */
    @GetMapping("/findShops")
    @ApiOperation(value = "查询商铺",notes = "查询商铺",tags = SwaggerConstants.API_SHOPPING)
    @Inner
    public R<IPage<ApiShoppingFromVo>> findShops(PageParam page ,ApiShopListDto shopListDto){
        //传入1是为了查询出审核通过的店铺
        return R.ok(shoppingService.getPageList(page,shopListDto,true,1));
    }

    /**
     * 新增商铺信息
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "新增商铺信息", notes = "新增商铺信息",tags = SwaggerConstants.API_SHOPPING)
    @PostMapping("/save")
    public R<Boolean> save(@Valid @RequestBody ApiShopAddDto obj){
        return R.ok(shoppingService.saveShop(obj));
    }

    /**
     * 更新店铺信息
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "更新店铺信息", notes = "更新店铺信息",tags = SwaggerConstants.API_SHOPPING)
    @PostMapping("/edit")
    public R<Boolean> edit(@Valid @RequestBody ApiShopEditDto obj){
        return R.ok(shoppingService.editShop(obj));
    }

    /**
     * 删除店铺信息
     * @param id 店铺id
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "删除店铺信息", notes = "删除店铺信息",tags = SwaggerConstants.API_SHOPPING)
    @ApiImplicitParam(value = "店铺信息Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(shoppingService.deleteShop(id));
    }


    /**
     * 商家上传微信收款二维码
     * @param:
     * @returns
     * @author hangdy
     * @date: 2020/11/12 15:59
     */
    @ApiOperation(value = "商家上传微信收款二维码", notes = "商家上传微信收款二维码",tags = SwaggerConstants.API_SHOPPING)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "店铺信息Id", name = "shopId", dataType = "Long", required = true),
            @ApiImplicitParam(value = "二维码地址", name = "codeUrl", dataType = "String", required = true)
    })
    @PutMapping("/QRcode")
    public R<Boolean> upQRCode(Long shopId,String codeUrl){
        return R.ok(shoppingService.upQRCode(shopId,codeUrl));
    }

    /**
     * 检查用户是否可以新增店铺 存在商铺就不能申请
     * @param:
     * @returns
     * @author hangdy
     * @date: 2020/11/20 11:00
     */
    @GetMapping("/checkAddShopping")
    @ApiOperation(value = "检查用户是否可以新增店铺", notes = "检查用户是否可以新增店铺",tags = SwaggerConstants.API_SHOPPING)
    public R<ApiAddShopingCheckVo> checkUserShopping(){
        return R.ok(shoppingService.checkUserAddShop());
    }

}
